package cn.ittaoli.szdz.service;

import cn.ittaoli.szdz.dao.CxMemberMapper;
import cn.ittaoli.szdz.dao.CxMemberMapperCustomer;
import cn.ittaoli.szdz.model.CxMember;
import cn.ittaoli.utils.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by lub_lenovo on 2017/11/8.
 */
@Service
public class IndexService {
    @Autowired
    private CxMemberMapper cxMemberMapper;

    @Autowired
    private CxMemberMapperCustomer cxMemberMapperCustomer;

    public CxMember findOne(){
        return cxMemberMapper.selectByPrimaryKey(1);
    }


    public String login(CxMember cxMember, String verify, String codeCorrect,HttpServletRequest request) {
        if(codeCorrect.equals(verify)){
            cxMember.setPassword(MD5.getMD5(cxMember.getPassword()));
            CxMember one = cxMemberMapperCustomer.findOne(cxMember);
            if(one!=null){
                request.getSession().setAttribute("user",one.getUser());
                request.getSession().setAttribute("id",one.getUid());

                return "1";
            }else{
                return "0";
            }

        }else{
            return "-1";
        }
    }
}
